package com.esender.ordermanage.listener;

import com.esender.ordermanage.config.RabbitMQConfig;
import com.esender.ordermanage.service.OrderManageService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;


@Component
public class DelayMessageListener {
    @Autowired
    private OrderManageService orderManageService;
    @RabbitListener(queues = {RabbitMQConfig.DEAD_QUEUE})
    public void receiveMessage(String msg, Channel channel, Message message) throws IOException {
        System.out.println("接收到消息：" + msg);
        orderManageService.delayCancelOrder(msg);

        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }
}
